<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/comm/comm.jsp"%>
  <script src="${ctx }/static/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="${ctx }/static/js/jquery.validate.min.js"></script>
<script type="text/javascript" src="${ctx }/static/js/layer/layer.js"></script>
<div class="row-fluid">
        <div class="span12"> 
          <!-- BEGIN SAMPLE FORM PORTLET-->
          <div class="portlet box red">
            <div class="portlet-title">
              <div class="caption"><i class="icon-reorder"></i>修改密码</div>
              <div class="tools"> <!-- <a href="javascript:;" class="collapse"></a> --> </div>
            </div>
            <div class="portlet-body form"> 
              <!-- BEGIN FORM-->
              <form action="" class="form-horizontal" id="updatepswForm" name="updatepswForm" method="post">
                <div class="row-fluid"> 
                  <!--/span-->
                  <div class="span6 ">
                    <div class="control-group">
                      <label class="control-label" for="">旧密码*</label>
                      <div class="controls">
                        <input id="oldpsw" name="oldpsw" class="m-wrap span12" placeholder="" type="password">
                      </div>
                    </div>
                  </div>
                 </div>
                 <div class="row-fluid">
                  <div class="span6 ">
                    <div class="control-group">
                      <label class="control-label" for="">新密码*</label>
                      <div class="controls">
                        <input id="newpsw" name="newpsw" class="m-wrap span12" placeholder="" type="password">
                      </div>
                    </div>
                  </div>
                 </div>
                 <div class="row-fluid">
                  <div class="span6 ">
                    <div class="control-group">
                      <label class="control-label" for="">确认密码*</label>
                      <div class="controls">
                        <input id="confirmpsw" name="confirmpsw" class="m-wrap span12" placeholder="" type="password">
                      </div>
                    </div>
                  </div>
                </div>
                <div class="form-actions">
                  <button type="button" onclick="doSubmit()"  class="btn red">保存</button>
                  <button type="reset" class="btn green">重置</button>
                </div>
              </form>
              
              <!-- END FORM--> 
              
            </div>
          </div>
          <!-- END SAMPLE FORM PORTLET--> 
        </div>
      </div>
      
      <script type="text/javascript">
      function doSubmit(){
      	$("#updatepswForm").submit();
      }
      $().ready(function(){
	 	$("#updatepswForm").validate({
	 		onkeyup:false,
	 		onfocusout:false,
	 		onclick: false,
	 		errorElement: "em",
	 		rules:{
				oldpsw:{
					required:true
				},
				newpsw:{
					required:true
				},
				confirmpsw:{
					required:true,
					equalTo:"#newpsw"
				}
			},
			messages:{
				oldpsw:{
					required:"<span style='color:red;font-size:10px;'>旧密码不能为空！</span>"
				},
				newpsw:{
					required:"<span style='color:red;font-size:10px;'>新密码不能为空！</span>"
				},
				confirmpsw:{
					required:"<span style='color:red;font-size:10px;'>确认密码不能为空！</span>",
					equalTo:"<span style='color:red;font-size:10px;'>确认密码与新密码不一致！</span>"
				}
			},
			submitHandler:function(form){
				$.ajax({
					url:'${ctx}/user/updatePsw',
					type:'post',
					data:$(form).serialize(),
					dataType:'json',
					success:function(res){
						if(res){
			 				if(res.code==200){
			 					layer.msg("修改成功！");
			 				}else{
			 					layer.msg(res.msg);
			 				}
			 			}else{
			 				layer.msg("服务器无响应...");
			 			}
					}
				})
			}
	 	});
	 });
      </script>